<template>
  <div>
    <template>
      <el-table :data="list" border stripe style="width: 100%">
        <el-table-column  label="序号" width="180" type="index" align="center"></el-table-column>
        <el-table-column prop="borrowAmount" label="借款额度" width="180"></el-table-column>
        <el-table-column prop="integralStart" label="积分区间开始" width="180"></el-table-column>
        <el-table-column prop="integralEnd" label="积分区间结束"></el-table-column>
        <el-table-column  label="操作">
          <template slot-scope="{row}">
            <router-link :to="`/core/integral-grade/edit/${row.id}`" style="margin-right:5px">
              <el-button el-button type="warning" size="small"  icon="el-icon-edit">修改 </el-button>
            </router-link>
            
            <el-button el-button type="danger" size="small" @click="deleteIntegral(row)" icon="el-icon-delete">删除 </el-button>
          </template>
        </el-table-column>
        
      </el-table>
    </template>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [],
    }
  },
  methods: {
    deleteIntegral(row){
      this.$confirm(`是否删除额度为${row.borrowAmount}, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
           this.deleteIntegralGrade(row.id)
           this.fetchData()
        }).catch(error => {
          //用户取消或者代码错误都会出现取消,这里我们只想展示用户取消的弹框
            if(error==='cancle'){
              this.$message({
             type: 'info',
              message: '已取消删除'
            });   
            }
                 
        });
    
    },
    async fetchData() {
      const result = await this.$API.integralGrade.getCoreList()
      if (result.code == 200) {
        this.list = result.data.list
      }
    },
    async deleteIntegralGrade(id){
      const result = await this.$API.integralGrade.deleteCore(id)
      if(result.code==200){
        this.$message({
          type:'success',
          message:result.message
        })
      }
    }
  },
  mounted() {
    this.fetchData()
  },
}
</script>

<style></style>
